const mybehavior = require("../../../../../behaviors/requests")
import Dialog from '@vant/weapp/dialog/dialog';
const baseUrl = "https://logisticsengineering.gree.com/pfep2_api/photo_manage/"
Page({
    /**
     * 页面的初始数据
     */
    behaviors: [mybehavior],
    data: {
        baseUrl: "https://logisticsengineering.gree.com/pfep2_api",
        page: 1,
        page_size: 5,
        query_cond: {},
        tb_key: "",
        permission_list: [],
        show: false,
        activeNames: ['1'],
        activeNames1: [],
        show_list: [],
        previewImageClick: false,
        row_data: {},
        record_show: false,
        steps: [],
        active: 0,
        ronqi_list: [],
        fucai_list: [],
        popup_show1: false,
        popup_show2: false,
        popup_show3: false,
        popup_show4: false,
        popup_show5: false,
        popup_show6: false,
        popup_show7: false,
        popup_show13: false,
        popup_show14: false,
        popup_show15: false,
        popup_show16: false,
        jiliang_options: ["个", "条", "米", "根", "件", "捆", "块",],
        show14: false,
        fenlei: {},
        columns: [],

        ronqi_list: [],
        ronqi_options: {},
        ronqi_options1: [],
        fucai_list: [],
        fucai_options: {},
        fucai_options1: [],
        params1: "",
        params2: "",
        params3: "",
        params4: "",
        ronqi_index: null,

        // infoData
        name: "",
        material_group: "",
        material_class: "",
        material_code: "",
        apply_unit: wx.getStorageSync('company'),

        // 容器库
        container: [
            {
                key: "s" + new Date().getTime(),
                容器名称: "",
                容器类别: "",
                容器编码: "",
                容器规格: "",
                用量: "",
            },

        ],
        // 辅材库
        auxiliayMaterial: [
            {
                key: "s" + new Date().getTime(),
                用量: "",
                辅材名称: "",
                辅材类别: "",
                辅材编码: "",
                辅材规格: "",
            }
        ],
        // packageData
        packageData: {
            单个物料重量d: "",
            单箱包装数b: "",
            单箱毛重: 0,
            容器自重: 0,
            最小包装数a: "",
            每箱数c: 0,
            计量单位: "",
        },
        // 操作说明
        standardData: {
            container: [],
            auxiliayMaterial: [],
            operationDescription: "",
            operationImageList: [

            ],
            identification: "",
            identificationImageList: [

            ],
            endingPackage: [
                {
                    key: "s" + new Date().getTime(),
                    order: "",
                    imageList: [

                    ]
                },

            ],

        },
        uploader: [],
        choose_img_btn_disabled: false,
        fileList: [],
        uploader1: [],
        choose_img_btn_disabled1: false,
        fileList1: [],
        uploader2: [],
        choose_img_btn_disabled2: false,
        fileList2: [],
        tb_key_list: [],
        tb_key: ""
    },
    // 提交模板数据
    submit() {
        let standardData1 = this.data.standardData
        standardData1.container = this.data.container
        standardData1.auxiliayMaterial = this.data.auxiliayMaterial
        let data = {
            content: {
                infoData: {
                    name: this.data.name,
                    material_group: this.data.material_group,
                    material_class: this.data.material_class,
                    material_code: this.data.material_code,
                    apply_unit: this.data.apply_unit,
                },
                packageData: this.data.packageData,
                standardData: standardData1,
                templateName: {
                    params1: this.data.params1,
                    params2: this.data.params2,
                    params3: this.data.params3,
                    params4: this.data.params4,
                }
            },
            receivers: [],
            sign_module: [],
            start_process: "",
            supply: "",
            use_in: "",
            unique_cond: {
                name: this.data.name + "模板",
                task_type: this.data.task_type,
                tb_key: this.data.tb_key,
            }
        }
        console.log("传过去的数据", data);
        // if (data.content.name=="") {

        // }
        let url = this.data.baseUrl + "/template_manage/add_template "

        this.post(url, data).then(res => {
            console.log("提交模板数据", res)


            if (res.code == 20000) {
                wx.showToast({
                    title: res.msg,
                    icon: 'success'
                })

                // this.setData({
                //     row_data: data_list[0].content,
                //     previewImageClick: true

                // })

            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })


    },

    // 照片选取1
    try_upload(e) {
        const self = this;
        self.setData({
            choose_img_btn_disabled: true
        })
        wx.chooseMedia({
            count: 1,
            mediaType: ['image'],
            sourceType: ['album', 'camera'],
            maxDuration: 30,
            camera: 'back',
            success(res) {
                const tempFilePath = res.tempFiles[0].tempFilePath;
                console.log(tempFilePath);
                wx.showLoading({
                    title: '开始上传。。。',
                })

                wx.uploadFile({
                    url: "https://logisticsengineering.gree.com/pfep2_api/photo_manage/fs_upload",
                    filePath: tempFilePath,
                    name: 'file',
                    formData: {
                    },
                    success(res) {
                        const result = JSON.parse(res.data);
                        console.log(result)
                        wx.hideLoading();
                        if (result.code == 20000) {
                            const uploader = self.data.uploader;
                            const new_uploader = uploader.concat({
                                url: baseUrl + "fs_download?file_id=" + result.data.file_id,
                                file_id: result.data.file_id,
                                isImage: true
                            })

                            self.setData({
                                uploader: new_uploader,
                                'standardData.operationImageList': new_uploader

                            })
                            if (self.data.uploader.length < 3) {
                                self.setData({
                                    choose_img_btn_disabled: false
                                })
                            }
                            wx.showToast({
                                title: '上传成功！',
                            })
                        } else {
                            if (self.data.uploader.length < 3) {
                                self.setData({
                                    choose_img_btn_disabled: false
                                })
                            }
                            wx.showToast({
                                title: result.msg,
                                icon: "error"
                            })
                        }

                    },
                    fail(res) {
                        wx.hideLoading();
                        if (self.data.uploader.length < 3) {
                            self.setData({
                                choose_img_btn_disabled: false
                            })
                        }
                        wx.showToast({
                            title: "未知错误428",
                            icon: "error"
                        })
                    }
                })

            },
            fail() {
                if (self.data.uploader.length < 3) {
                    self.setData({
                        choose_img_btn_disabled: false
                    })
                }
            }



        })
    },
    handle_delete(e) {
        const index = e.detail.index;
        const file = this.data.uploader[index];
        const file_id = file.url.split("=")[1];
        const uploader = this.data.uploader;
        const self = this;
        let url1 = baseUrl + 'fs_delete'
        let data = {
            file_id
        }
        this.post(url1, data).then(res => {
            if (res.code == 20000) {
                wx.showToast({
                    title: res.msg,
                    icon: 'success'
                })

                uploader.splice(index, 1);
                self.setData({
                    choose_img_btn_disabled: false,
                })
                self.setData({
                    uploader
                });


            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })
    },
    // 照片选取2
    try_upload1(e) {
        const self = this;
        self.setData({
            choose_img_btn_disabled1: true
        })
        wx.chooseMedia({
            count: 1,
            mediaType: ['image'],
            sourceType: ['album', 'camera'],
            maxDuration: 30,
            camera: 'back',
            success(res) {
                const tempFilePath = res.tempFiles[0].tempFilePath;
                console.log(tempFilePath);
                wx.showLoading({
                    title: '开始上传。。。',
                })

                wx.uploadFile({
                    url: "https://logisticsengineering.gree.com/pfep2_api/photo_manage/fs_upload",
                    filePath: tempFilePath,
                    name: 'file',
                    formData: {
                    },
                    success(res) {
                        const result = JSON.parse(res.data);
                        console.log(result)
                        wx.hideLoading();
                        if (result.code == 20000) {
                            const uploader = self.data.uploader1;
                            const new_uploader = uploader.concat({
                                url: baseUrl + "fs_download?file_id=" + result.data.file_id,
                                file_id: result.data.file_id,
                                isImage: true
                            })

                            self.setData({
                                uploader1: new_uploader,
                                'standardData.identificationImageList': new_uploader

                            })
                            if (self.data.uploader1.length < 3) {
                                self.setData({
                                    choose_img_btn_disabled1: false
                                })
                            }
                            wx.showToast({
                                title: '上传成功！',
                            })
                        } else {
                            if (self.data.uploader1.length < 3) {
                                self.setData({
                                    choose_img_btn_disabled1: false
                                })
                            }
                            wx.showToast({
                                title: result.msg,
                                icon: "error"
                            })
                        }

                    },
                    fail(res) {
                        wx.hideLoading();
                        if (self.data.uploader1.length < 3) {
                            self.setData({
                                choose_img_btn_disabled1: false
                            })
                        }
                        wx.showToast({
                            title: "未知错误428",
                            icon: "error"
                        })
                    }
                })

            },
            fail() {
                if (self.data.uploader1.length < 3) {
                    self.setData({
                        choose_img_btn_disabled1: false
                    })
                }
            }



        })
    },
    handle_delete1(e) {
        const index = e.detail.index;
        const file = this.data.uploader1[index];
        const file_id = file.url.split("=")[1];
        const uploader = this.data.uploader1;
        const self = this;
        console.log("111", file);
        console.log("222", uploader);
        let url1 = baseUrl + 'fs_delete'
        let data = {
            file_id
        }
        this.post(url1, data).then(res => {
            if (res.code == 20000) {
                wx.showToast({
                    title: res.msg,
                    icon: 'success'
                })

                uploader.splice(index, 1);
                self.setData({
                    choose_img_btn_disabled: false,
                })
                self.setData({
                    uploader1:uploader
                });


            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })


    },

    // 照片选取3
    try_upload2(e) {
        console.log(e.currentTarget.dataset.row_index);
        let i = e.currentTarget.dataset.row_index
        let arr = this.data.standardData.endingPackage
        console.log("aaa", arr);
        const self = this;
       
        wx.chooseMedia({
            count: 1,
            mediaType: ['image'],
            sourceType: ['album', 'camera'],
            maxDuration: 30,
            camera: 'back',
            success(res) {
                const tempFilePath = res.tempFiles[0].tempFilePath;
                console.log(tempFilePath);
                wx.showLoading({
                    title: '开始上传。。。',
                })

                wx.uploadFile({
                    url: "https://logisticsengineering.gree.com/pfep2_api/photo_manage/fs_upload",
                    filePath: tempFilePath,
                    name: 'file',
                    formData: {
                    },
                    success(res) {
                        const result = JSON.parse(res.data);
                        console.log(result)
                        wx.hideLoading();
                        if (result.code == 20000) {
                            const uploader = arr[i].imageList;
                            console.log("xxxx", arr[i].imageList);
                            const new_uploader = uploader.concat({
                                url: baseUrl + "fs_download?file_id=" + result.data.file_id,
                                file_id: result.data.file_id,
                                isImage: true

                            })


                            arr[i].imageList = new_uploader
                            self.setData({
                                'standardData.endingPackage': arr


                            })
                            console.log("12312321", new_uploader);
                            console.log("aaa", self.data.standardData.endingPackage);
                            if (self.data.standardData.endingPackage[i].imageList.length < 3) {
                                wx.showToast({
                                    title: '最多上传三张图片！！',
                                    icon:'error'
                                  })
                            }
                            wx.showToast({
                                title: '上传成功！',
                            })
                        } else {
                            if (self.data.standardData.endingPackage[i].imageList.length < 3) {
                               wx.showToast({
                                 title: '最多上传三张图片！！',
                                 icon:'error'
                               })
                            }
                            // wx.showToast({
                            //     title: result.msg,
                            //     icon: "error"
                            // })
                        }

                    },
                    fail(res) {
                        wx.hideLoading();
                        if (self.data.standardData.endingPackage[i].imageList.length < 3) {
                            wx.showToast({
                                title: '最多上传三张图片！！',
                                icon:'error'
                              })
                        }
                        // wx.showToast({
                        //     title: "未知错误428",
                        //     icon: "error"
                        // })
                    }
                })

            },
            fail() {
                if (self.data.standardData.endingPackage[i].imageList.length < 3) {
                    self.setData({
                        choose_img_btn_disabled2: false
                    })
                }
            }



        })
    },
    handle_delete2(e) {
        let i = e.currentTarget.dataset.row_index
        console.log("cxxx", i);
        let arr = this.data.standardData.endingPackage
        const index = e.detail.index;
        const file = this.data.standardData.endingPackage[i].imageList[index];
        const file_id = file.url.split("=")[1];
        const uploader = this.data.standardData.endingPackage[i].imageList;
        const self = this;
        console.log("111", file);
        console.log("222", uploader);
        let url1 = baseUrl + 'fs_delete'
        let data = {
            file_id
        }
        this.post(url1, data).then(res => {
            if (res.code == 20000) {
                wx.showToast({
                    title: res.msg,
                    icon: 'success'
                })

                arr[i].imageList.splice(index, 1)

                self.setData({
                    choose_img_btn_disabled2: false,
                })
                self.setData({
                    'standardData.endingPackage': arr
                });


            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })


    },

    // 预览照片
    previewPhoto(e) {
        let img_url = "https://logisticsengineering.gree.com/pfep2_api/photo_manage/fs_download?file_id=" + e.currentTarget.dataset.row_data
        console.log(img_url);
        let u = []
        u.push(img_url)
        wx.previewImage({
            current: img_url,
            urls: u,
        })
    },


    // 获取计量单位数据
    getUnitDatas(e) {

        let url = this.data.baseUrl + "/unities_manage/query_unities "
        let data = {
            unity_type: "",
            name: "",
        }
        this.post(url, data).then(res => {
            // console.log("获取计量单位数据", res)
            let data_list = res.data.results


            if (res.code == 20000) {

                // this.setData({
                //     row_data: data_list[0].content,
                //     previewImageClick: true

                // })

            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })
    },

    // 获取--供应商--数据
    getPermissionDatas() {
        let url = this.data.baseUrl + "/data_auth_manage/get_u_permission"
        let data = {

        }
        this.post(url, data).then(res => {
            // console.log("获取供应商数据", res.data)
            let data_list = Object.keys(res.data)
            // console.log("xxx", data_list);

            if (res.code == 20000) {

                this.setData({
                    permission_list: data_list,
                    previewImageClick: true

                })

            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })
    },
    // 获取--容器库--数据
    getRonqisDatas() {
        let url = this.data.baseUrl + "/container_manage/query_containers"
        let data = {
            page: 1,
            page_size: 9999,
            query_cond: {
                "content.database": "容器库"
            },
        }
        this.post(url, data).then(res => {
            // console.log("获取--容器库--数据", res.data.results)
            let res_list = res.data.results
            let list1 = []
            for (let i in res_list) {
                list1.push(res_list[i].content)
            }
            // console.log(list1);
            let obj = {}
            for (let j in list1) {
                let obj1 = {
                    [list1[j].category]: []
                }

                obj = Object.assign(obj, obj1)
            }
            for (let k in list1) {
                for (let l in Object.keys(obj)) {
                    if (list1[k].category == Object.keys(obj)[l]) {
                        obj[Object.keys(obj)[l]].push(list1[k].size)
                    }
                }
            }
            // console.log("zxc111", obj);

            let arr = Object.keys(obj)
            if (res.code == 20000) {
                this.setData({
                    ronqi_list: arr,
                    ronqi_options: obj,
                    previewImageClick: true

                })

            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })
    },
    // 获取--辅材库--数据
    getFucaiDatas() {
        let url = this.data.baseUrl + "/container_manage/query_containers"
        let data = {
            page: 1,
            page_size: 9999,
            query_cond: {
                "content.database": "辅材库"
            },
        }
        this.post(url, data).then(res => {
            // console.log("获取--辅材库--数据", res.data.results)
            let res_list = res.data.results
            let list1 = []
            for (let i in res_list) {
                list1.push(res_list[i].content)
            }

            // console.log(list1);
            let obj = {}
            for (let j in list1) {
                let obj1 = {
                    [list1[j].category]: []
                }

                obj = Object.assign(obj, obj1)
            }
            for (let k in list1) {
                for (let l in Object.keys(obj)) {
                    if (list1[k].category == Object.keys(obj)[l]) {
                        obj[Object.keys(obj)[l]].push(list1[k].size)
                    }
                }
            }
            // console.log("zxc", obj);
            let arr = Object.keys(obj)
            if (res.code == 20000) {
                this.setData({
                    fucai_list: arr,
                    fucai_options: obj,
                    previewImageClick: true

                })

            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })
    },

    // 折叠面板
    onChange(event) {
        this.setData({
            activeNames: event.detail,
        });
    },
    // 折叠面板
    onChange1(event) {
        this.setData({
            activeNames1: event.detail,
        });
    },

    // 点击--适用单位--选取输入框
    onClick1(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show1: true
        })
    },
    // 选择--适用单位--输入框关闭
    onClose11() {
        this.setData({ popup_show1: false });
    },
    // 确认--适用单位--值--弹出框关闭
    onChange11(event) {
        const { picker, value, index } = event.detail;
        this.setData({
            "row_data.infoData.apply_unit": value,
            popup_show1: false,
        })
    },

    // 点击--适用单位--选取输入框
    onClick12(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show2: true
        })
    },
    // 选择--适用单位--输入框关闭
    onClose12() {
        this.setData({ popup_show2: false });
    },
    // 确认--适用单位--值--弹出框关闭
    onChange12(event) {
        const { picker, value, index } = event.detail;
        console.log(value);
        this.setData({
            // "row_data.infoData.apply_unit": value,
            popup_show1: false,
        })
    },


    // 获取--分类--数据
    getDirDatas(e) {
        let url = this.data.baseUrl + "/folders_manage/query_dir"
        let data = {
            route_name: e
        }
        this.post(url, data).then(res => {
            // console.log("获取--分类--数据", res.data)
            let res_list = res.data.folders
            // console.log("获取--分类--数据", res_list)
            let obj = {}
            let obj2 = {}
            for (let i in res_list) {
                let obj1 = {
                    [res_list[i].name]: [],

                }

                // console.log("sdfsf", obj3);
                for (let j in res_list[i].child) {
                    obj1[[res_list[i].name]].push(res_list[i].child[j].name)
                    let obj3 = {
                        [res_list[i].child[j].name]: res_list[i].child[j].index,

                    }
                    obj2 = Object.assign(obj2, obj3)

                }
                obj = Object.assign(obj, obj1)

            }
            // console.log("AA", obj2);
            let columns1 = [
                {
                    values: Object.keys(obj),
                    className: 'column1',
                },
                {
                    values: obj[Object.keys(obj)[0]],
                    className: 'column2',
                    defaultIndex: 2,
                },
            ]
            // console.log("BB", columns1);

            if (res.code == 20000) {
                this.setData({
                    fenlei: obj,
                    columns: columns1,
                    tb_key_list: obj2

                })

            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })
    },
    // 点击--模板信息--选取输入框
    onClick14(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            show14: true,
        })
    },
    // 生产名称
    onConfirm14() {
        let val = this.data.params1 + this.data.params2 + this.data.params3
        this.setData({
            show14: false,
            name: val
        })
    },
    // 点击--模板信息--选取输入框
    onClick13(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show13: true,
        })
    },
    // 选择--模板信息--输入框关闭
    onClose13() {
        this.setData({ popup_show13: false });
    },
    // 选择--模板信息--输入框关闭
    onChange13(event) {
        const { picker, value, index } = event.detail;
        picker.setColumnValues(1, this.data.fenlei[value[0]]);
    },
    // 选择--模板信息--输入框确定
    onConfirm13(event) {
        console.log(event.detail);
        let key = this.data.tb_key_list[event.detail.value[1]]
        this.setData({
            popup_show13: false,
            params1: event.detail.value[1],
            tb_key: key

        })
    },

    // 点击--容器类别--选取输入框
    onClick15(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show15: true
        })
    },
    // 选择--容器类别--输入框关闭
    onClose15() {
        this.setData({ popup_show15: false });
    },
    // 确认--容器类别--值--弹出框关闭
    onChange15(event) {
        const { picker, value, index } = event.detail;
        console.log(value);
        let obj = this.data.ronqi_options
        this.setData({
            params2: value,
            ronqi_options1: obj[value],
            popup_show15: false,
        })
    },




    // 点击--容器类别--选取输入框
    onClick3(event) {
        console.log(event);
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show3: true,
            ronqi_index: event.currentTarget.dataset.row_data
        })
    },
    // 选择--容器类别--输入框关闭
    onClose3() {
        this.setData({ popup_show3: false });
    },
    // 确认--容器类别333--值--弹出框关闭
    onChange3(event) {
        const { picker, value, index } = event.detail;
        let container1 = this.data.container
        let i = this.data.ronqi_index

        let obj = container1[i]
        container1[i]['容器类别'] = value
        let options1 = this.data.ronqi_options
        console.log("xxx", obj);
        this.setData({
            container: container1,
            ronqi_options1: options1[value],
            popup_show3: false,
        })
    },
    // 删除一项容器
    deleteRonqi(e) {
        console.log(e.currentTarget.dataset.row_data);
        let i = e.currentTarget.dataset.row_data
        let lists = this.data.container;
        lists.splice(i, 1);
        console.log("xxx", lists);
        this.setData({
            container: lists,
        })


    },
    // 新增一项容器
    addRonqi(e) {
        let lists = this.data.container;
        let t = "s" + new Date().getTime()
        let newData = {
            key: t,
            容器名称: "",
            容器类别: "",
            容器编码: "",
            容器规格: "",
            用量: "",
        };
        lists.push(newData);//实质是添加lists数组内容，使for循环多一次
        console.log("xxx", lists);
        this.setData({
            container: lists,
        })

    },
    // 点击--容器尺寸--选取输入框
    onClick16(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show16: true
        })
    },
    // 选择--容器尺寸--输入框关闭
    onClose16() {
        this.setData({ popup_show16: false });
    },
    // 确认--容器尺寸--值--弹出框关闭
    onChange16(event) {
        const { picker, value, index } = event.detail;
        console.log(value);
        this.setData({
            params3: value,
            popup_show16: false,
        })
    },

    // 点击--容器尺寸--选取输入框
    onClick4(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show4: true,
            ronqi_index: event.currentTarget.dataset.row_data

        })
    },
    // 选择--容器尺寸--输入框关闭
    onClose4() {
        this.setData({ popup_show4: false });
    },
    // 确认--容器尺寸--值--弹出框关闭
    onChange4(event) {
        const { picker, value, index } = event.detail;
        let container1 = this.data.container
        let i = this.data.ronqi_index

        let obj = container1[i]
        container1[i]['容器规格'] = value
        container1[i]['容器名称'] = container1[i]['容器类别'] + container1[i]['容器规格']
        this.setData({
            container: container1,
            popup_show4: false,
        })
    },
    // 容器--用量--字段数据双向绑定
    bindInput(e) {
        let container1 = this.data.container
        let i = e.currentTarget.dataset.row_index
        let val = e.currentTarget.dataset.row_val
        container1[i][val] = e.detail
        this.setData({
            container: container1,
        })
    },




    // 点击--辅材类别--选取输入框
    onClick5(event) {
        console.log(event);
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show5: true,
            fucai_index: event.currentTarget.dataset.row_data
        })
    },
    // 选择--辅材类别--输入框关闭
    onClose5() {
        this.setData({ popup_show5: false });
    },
    // 确认--辅材类别--值--弹出框关闭
    onChange5(event) {
        const { picker, value, index } = event.detail;
        let auxiliayMaterial1 = this.data.auxiliayMaterial
        let i = this.data.fucai_index

        let obj = auxiliayMaterial1[i]
        auxiliayMaterial1[i]['辅材类别'] = value
        let options1 = this.data.fucai_options
        console.log("xxx", obj);
        this.setData({
            auxiliayMaterial: auxiliayMaterial1,
            fucai_options1: options1[value],
            popup_show5: false,
        })
    },
    // 点击--辅材尺寸--选取输入框
    onClick6(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show6: true,
            fucai_index: event.currentTarget.dataset.row_data

        })
    },
    // 选择--辅材尺寸--输入框关闭
    onClose6() {
        this.setData({ popup_show6: false });
    },
    // 确认--辅材尺寸--值--弹出框关闭
    onChange6(event) {
        const { picker, value, index } = event.detail;
        let auxiliayMaterial1 = this.data.auxiliayMaterial
        let i = this.data.fucai_index

        let obj = auxiliayMaterial1[i]
        auxiliayMaterial1[i]['辅材规格'] = value
        auxiliayMaterial1[i]['辅材名称'] = auxiliayMaterial1[i]['辅材类别'] + auxiliayMaterial1[i]['辅材规格']
        this.setData({
            auxiliayMaterial: auxiliayMaterial1,
            popup_show6: false,
        })
    },
    // 辅材--用量--字段数据双向绑定
    bindInput1(e) {
        let auxiliayMaterial1 = this.data.auxiliayMaterial
        let i = e.currentTarget.dataset.row_index
        let val = e.currentTarget.dataset.row_val
        auxiliayMaterial1[i][val] = e.detail
        this.setData({
            auxiliayMaterial: auxiliayMaterial1,
        })
    },


    // 删除一项辅材
    deleteFucai(e) {
        console.log(e.currentTarget.dataset.row_data);
        let i = e.currentTarget.dataset.row_data
        let lists = this.data.auxiliayMaterial;
        lists.splice(i, 1);
        console.log("xxx", lists);
        this.setData({
            auxiliayMaterial: lists,
        })


    },
    // 新增一项辅材
    addFucai(e) {
        let lists = this.data.auxiliayMaterial;
        let t = "s" + new Date().getTime()
        let newData = {
            key: t,
            用量: "",
            辅材名称: "",
            辅材类别: "",
            辅材编码: "",
            辅材规格: "",
        };
        lists.push(newData);//实质是添加lists数组内容，使for循环多一次
        console.log("xxx", lists);
        this.setData({
            auxiliayMaterial: lists,
        })

    },
    // 包装信息---字段数据双向绑定
    bindInput2(e) {
        let packageData1 = this.data.packageData
        let val = e.currentTarget.dataset.row_val



        packageData1[val] = e.detail
        packageData1['每箱数c'] = packageData1['最小包装数a'] * packageData1['单箱包装数b']
        packageData1['单箱毛重'] = packageData1['单箱包装数b'] * packageData1['单个物料重量d']
        this.setData({
            packageData: packageData1,
        })
    },
    // 点击--计量单位--选取输入框
    onClick7(event) {
        // event.detail 为当前输入的值
        // console.log(event.detail);
        this.setData({
            popup_show7: true
        })
    },
    // 选择--计量单位--输入框关闭
    onClose7() {
        this.setData({ popup_show7: false });
    },
    // 确认--计量单位--值--弹出框关闭
    onChange7(event) {
        const { picker, value, index } = event.detail;
        let packageData1 = this.data.packageData
        packageData1['计量单位'] = value
        this.setData({
            packageData: packageData1,
            popup_show7: false,
        })
    },


    // 新增一项--尾数包装要求
    addEndData(e) {
        let lists = this.data.standardData.endingPackage;
        let t = "s" + new Date().getTime()
        let newData =
        {
            key: t,
            order: "",
            imageList: [

            ]
        }

        lists.push(newData);//实质是添加lists数组内容，使for循环多一次
        this.setData({
            'standardData.endingPackage': lists,
        })
        console.log("xxx", this.data.standardData.endingPackage);

    },


    // 删除一项--尾数包装要求
    deleteFucai(e) {
        console.log(e.currentTarget.dataset.row_data);
        let i = e.currentTarget.dataset.row_data
        let lists = this.data.standardData.endingPackage;
        lists.splice(i, 1);
        console.log("xxx", lists);
        this.setData({
            'standardData.endingPackage': lists,
        })


    },
    // 尾数包装---字段数据双向绑定
    bindInput3(e) {
        // console.log(e.currentTarget.dataset.row_index);

        let i = e.currentTarget.dataset.row_index
        let lists = this.data.standardData.endingPackage;

        lists[i].order = e.detail
        this.setData({
            'standardData.endingPackage': lists,
        })
        // console.log(this.data.standardData.endingPackage);
    },
    // 操作说明---字段数据双向绑定
    bindInput4(e) {
        console.log(e.detail);


        this.setData({
            'standardData.operationDescription': e.detail,
        })
        // console.log(this.data.standardData.endingPackage);
    },
    // 标识要求---字段数据双向绑定
    bindInput5(e) {
        console.log(e.detail);


        this.setData({
            'standardData.identification': e.detail,
        })
        // console.log(this.data.standardData.endingPackage);
    },



    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // console.log(options);
        this.setData({
            material_group: options.citg,
            material_class: options.cpcl,
            material_code: options.material_num,
        })
        let self = this
        const eventChannel = this.getOpenerEventChannel()
        // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
        eventChannel.on('acceptDataFromOpenerPage', function (data) {
            console.log("传过来的数据", data)
            let arr = data.content.standardData.operationImageList
            let arr1 = data.content.standardData.identificationImageList
            let arr2 = data.content.standardData.endingPackage
            let image_list = []
            let image_list1 = []
            let image_list2 = []
            for (let i in arr) {
                let obj = {
                    isImage: true,
                    url: "",
                    file_id: ""

                }
                obj.url =  baseUrl + "fs_download?file_id=" + arr[i].file_id
                obj.file_id = arr[i].file_id
                image_list.push(obj)
            }
            for (let j in arr1) {
                let obj = {
                    isImage: true,
                    url: "",
                    file_id: ""

                }
                obj.url = baseUrl + "fs_download?file_id=" + arr1[j].file_id
                obj.file_id = arr1[j].file_id
                image_list1.push(obj)
            }
            for(let k in arr2){
                for(let l in arr2[k].imageList){
                    let obj = {
                        isImage: true,
                        url: "",
                        file_id: ""
    
                    }
                    obj.url = baseUrl + "fs_download?file_id=" + arr2[k].imageList[l].file_id
                    obj.file_id = arr2[k].imageList[l].file_id
                    image_list2.push(obj)
                }
                arr2[k].imageList = image_list2
            }
            data.content.standardData.operationImageList= arr
            data.content.standardData.identificationImageList= arr1
            data.content.standardData.endingPackage= arr2
            console.log("传过来的数据1111", data)
            self.setData({
                uploader:image_list,
                uploader1:image_list1,
                row_data: data,
                container: data.content.standardData.container,
                auxiliayMaterial: data.content.standardData.auxiliayMaterial,
                standardData: data.content.standardData,
                packageData: data.content.packageData,
            })
            // let obj = {
            //     "content.infoData.material_code": data.material_code,
            //     use_in: data.use_in

            // }
            // console.log("123345", obj)
            // self.getDatas(obj)

        })
        // console.log(options);
        // if (options.route_name.length != undefined) {
        //     this.setData({
        //         task_type: options.route_name
        //     })
        //     this.getDirDatas(options.route_name)
        // }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        if (this.data.previewImageClick == false) {
            this.getPermissionDatas()
            this.getRonqisDatas()
            this.getFucaiDatas()
            this.getUnitDatas()

        }

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})